/// <reference path="../Scripts/jquery-1.7.1.min.js" />
/// <reference path="../Scripts/knockout-2.1.0.js" />

function ApplicationUserViewModel() 
	{
    var self = this;
	// put a property loop here
	self.ApplicationUserID = ko.observable();
			self.TS = ko.observable();
			self.CreatedBy = ko.observable();
			self.CreatedDt = ko.observable();
			self.ModifiedBy = ko.observable();
			self.ModifiedDt = ko.observable();
			self.UserId = ko.observable();
			self.ApplicationID = ko.observable();
			self.Action = ko.observable();
			self.Caller = ko.observable();
			self.Role = ko.observable();
			self.PageSize = ko.observable();
			self.PageNumber = ko.observable();
			self.SortColumn = ko.observable();
			self.SortType = ko.observable();
			self.TotalRows = ko.observable();
    
    self.ApplicationUserList = ko.observableArray([]);
    self.setApplicationUser = function (
			ApplicationUserID, TS, CreatedBy, CreatedDt, ModifiedBy, ModifiedDt, UserId, ApplicationID, _Action, _Caller, _Role, _PageNumber, _PageSize, _SortColumn, _SortType, _TotalRows 
	
	) {

	ApplicationUserID = _ApplicationUserID;
			TS = _TS;
			CreatedBy = _CreatedBy;
			CreatedDt = _CreatedDt;
			ModifiedBy = _ModifiedBy;
			ModifiedDt = _ModifiedDt;
			UserId = _UserId;
			ApplicationID = _ApplicationID;
			Action = _Action;
			Caller = _Caller;
			Role = _Role;
			PageSize = _PageSize
			PageNumber = _PageNumber;
			SortColumn = _SortColumn;
			SortType = _SortType;
			TotalRows = _TotalRows;
        
    }; //  End of set procedure 

	self.AddApplicationUser = function () {

        //alert("We are in the AddApplicationUser ko function");
       
        this.Action = "Add";
        this.Caller = "trooks"; //Adjust the caller by calling the AccountViewModel
        this.Role = "user"; //Adjust the role by calling the AccountViewModel
        var myData = ko.toJSON(this);
        jQuery.ajax({
            url: "/api/ApplicationUserapi/",
            type: 'post',
            data: myData,
            contentType: 'application/json',
            success: function (result) {
                alert(result);
            }
        });



    }; //End of add procedure

    self.GetApplicationUserByParameter = function () {
        this.Action = "GetAll";
        this.Caller = "trooks";
        this.Role = "user";
        this.PageNumber = 1;
        this.PageSize = 10;
        this.SortColumn = "ApplicationUserID";
        this.SortType = "asc";
        var myData = ko.toJSON(this);
        jQuery.ajax({
            url: "/api/ApplicationUserapi/",
            type: 'get',
            data: myData,
            contentType: 'application/json',
            success: function (data) {
                $.each(data, function (key, val) {
                    //alert("We have loaded the values and are in the each module.");
                    self.ApplicationList.push(
                        self.SetApplication(
			val.ApplicationUserID, 
			val.TS, 
			val.CreatedBy, 
			val.CreatedDt, 
			val.ModifiedBy, 
			val.ModifiedDt, 
			val.UserId, 
			val.ApplicationID, 
			val.Action,
			val.Caller,
			val.Role,
			val.PageSize,
			val.PageNumber,
			val.SortColumn,
			val.SortType,
			val.TotalRows

                        ));
                });
            }
        });
    };
			

}; //End of view model





